package xyz.lwm.lazycat.netpipe.controller;

import xyz.lwm.lazycat.annotation.Inject;
import xyz.lwm.lazycat.netpipe.domain.entity.User;
import xyz.lwm.lazycat.netpipe.domain.vo.Token;
import xyz.lwm.lazycat.netpipe.service.AuthService;
import xyz.lwm.lazycat.utility.Assert;
import xyz.lwm.lazycat.utility.R;
import xyz.lwm.lazycat.utility.StringUtil;
import xyz.lwm.lazycat.web.annocation.Body;
import xyz.lwm.lazycat.web.annocation.Controller;
import xyz.lwm.lazycat.web.annocation.Post;

import java.lang.reflect.InvocationTargetException;

import static xyz.lwm.lazycat.netpipe.util.Constants.ROOT_PATH;

/**
 * 登录
 *
 * @author lwm
 */
@Controller(ROOT_PATH)
public class LoginController {

    @Inject
    private AuthService authService;

    @Post("login")
    public R<Token> login(@Body User user) {
        Assert.isTrue(StringUtil.isNotBlank(user.getUsername()),  "用户名不能为空");
        Assert.isTrue(StringUtil.isNotBlank(user.getPassword()),  "密码不能为空");
        Token token = authService.login(user);
        return R.ok(token);
    }

}
